/**
 * 公司：金丹科技
 * 文件：MyConfig
 * 作者：kong
 * 时间：2019/4/16 11:57
 * 描述：
 */

package com.springboot.test.config;
import com.springboot.test.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("success");
    }

    @Bean
    public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
        WebMvcConfigurerAdapter webMvcConfigurerAdapter = new WebMvcConfigurerAdapter() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("index");
                registry.addViewController("/index.html").setViewName("index");
                registry.addViewController("/main.html").setViewName("dashboard");
            }
//                Spring boot 已经做好了静态资源的释放工作。
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
//                 registry.addInterceptor(new LoginHanderinterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html",
//                         "/","/user/login");
            }
        };
        return webMvcConfigurerAdapter;
    }

    @Bean
     public LocaleResolver localeResolver(){
        return  new MyLocaleResolver();
     }


}
